package com.better.frontend.service.studentScore;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.better.backend.dataComputingService.model.examAvg.ExamAvgCalModel;
import com.better.backend.dataComputingService.model.examAvg.ExamClassAvgCalModel;
import com.better.backend.dataComputingService.model.examAvg.ExamSubjectAvgCalModel;
import com.better.backend.dataComputingService.model.examAvg.ExamSubjectSchoolAvgCalModel;
import com.better.backend.dataComputingService.model.point.ExamSubjectStuPointCalModel;
import com.better.backend.dataComputingService.model.point.PointCalModel;
import com.better.backend.dataComputingService.model.point.PointStuCalModel;
import com.better.backend.dataComputingService.model.point.StudentPointCalModel;
import com.better.backend.dataComputingService.model.question.ExamSubjectStuQuestionCalModel;
import com.better.backend.dataComputingService.model.question.QuestionStuCalModel;
import com.better.backend.dataComputingService.model.question.StudentQuestionCalModel;
import com.better.backend.dataComputingService.model.scoreSelection.SeleExamStudentScoreCalModel;
import com.better.backend.dataComputingService.model.stuScore.ExamStudentScoreCalModel;
import com.better.backend.dataComputingService.model.stuScore.StudentScoreCalModel;
import com.better.backend.dataComputingService.model.stuScore.SubujectScoreCalModel;
import com.better.backend.dataComputingService.repository.examAvgRespository.ExamAvgRepsitory;
import com.better.backend.dataComputingService.repository.pointRespository.PointRepsitory;
import com.better.backend.dataComputingService.repository.questionRespository.QuestionRepsitory;
import com.better.backend.dataComputingService.repository.scoreSelection.SeleExamStudentScoreRepsitory;
import com.better.backend.dataComputingService.repository.stuScoreRespository.ExamStuScoRepsitory;
import com.better.backend.mqReceiverService.examReceiver.model.ExamModel;
import com.better.backend.mqReceiverService.examReceiver.model.ExamUnitModel;
import com.better.backend.mqReceiverService.examReceiver.model.SubjectScoreModel;
import com.better.backend.mqReceiverService.examReceiver.repository.ExamRepsitory;
import com.better.backend.mqReceiverService.questionReceiver.model.ExamPaperModel;
import com.better.backend.mqReceiverService.questionReceiver.model.QuestionModel;
import com.better.backend.mqReceiverService.questionReceiver.repository.ExamPaperRepsitory;
import com.better.backend.mqReceiverService.studentRecever.model.ScoreReceverModel;
import com.better.backend.mqReceiverService.studentRecever.model.StuScoreDetailModel;
import com.better.backend.mqReceiverService.studentRecever.model.StuScoreReceverModel;
import com.better.backend.mqReceiverService.studentRecever.repository.ScoreReceverModelRepository;
import com.better.common.base.ServiceResponse;
import com.better.common.exception.DescribeException;
import com.better.common.mq.HiSender;
import com.better.common.mq.MqTopic;
import com.better.common.utils.CloneUtil;
import com.better.common.utils.CmsHttpPostUtil;
import com.better.common.utils.GlobalUtil;
import com.better.common.utils.ServiceResponseHandle;
import com.better.consist.CalTypeEnum;
import com.better.consist.ExamEnum;
import com.better.consist.GlobalTypeEnum;
import com.better.frontend.Iservice.studentScore.StudentScoreService;
import com.better.frontend.model.studentScore.ScoreAyalysModel;
import com.better.frontend.model.studentScore.StuCompModel;
import com.better.frontend.model.studentScore.StudentScoreNumVo;
import com.better.frontend.vo.studentScore.*;
import com.better.util.BigDecimalUtils;
import com.better.util.FiledAliasMapUtils;
import com.better.util.MapUtils;
import com.better.util.excelUtil.ImportExcel;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingLong;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;


/**
 * Created by wfm on 2017/11/11.
 */
@Service
public class StudentScoreServiceImp<T> implements StudentScoreService<T> {
    @Autowired
    private ExamStuScoRepsitory examStuScoRepsitory;
    @Autowired
    private ExamAvgRepsitory examAvgRepsitory;
    @Autowired
    private PointRepsitory pointRepsitory;
    @Autowired
    private QuestionRepsitory questionRepsitory;
    @Autowired
    private ScoreReceverModelRepository scoreReceverModelRepository;
    @Autowired
    private ExamPaperRepsitory examPaperRepsitory;
    @Value("${studentUrl}")
    private String studentUrl;
    @Value("${classListUrl}")
    private String classListUrl;
    @Autowired
    private HiSender hiSender;
    @Autowired
    private ExamRepsitory examRepsitory;
    @Autowired
    private SeleExamStudentScoreRepsitory seleExamStudentScoreRepsitory;
    private Log logger = LogFactory.getLog(StudentScoreServiceImp.class);


    /**
     * 查看成绩
     *
     * @author:
     * @date :2017/11/21
     */
    @Override
    public Page<ExamStudentScoreCalModel> getStudentScore(ExamStudentScoreCalModel scoreModel, Integer pageIndex, Integer pageSize) {
        Page<ExamStudentScoreCalModel> page = examStuScoRepsitory.findPageBy(MapUtils.java2Map(scoreModel), pageIndex, pageSize);
        //分页查询，拆分嵌套对象，实现单条数据嵌套数据分页
/*        Map<String, Object> querParms = new HashMap<String, Object>();
       // querParms=MapUtils.java2Map(scoreModel);
        querParms.put("examId",scoreModel.getExamId());
        querParms.put("schoolId",scoreModel.getSchoolId());
        querParms.put("gradeId",scoreModel.getGradeId());
        querParms.put("classId",scoreModel.getClassId());
        ExamStudentScoreCalVO bean=new ExamStudentScoreCalVO();
        Map<String, String> filedAlias= FiledAliasMapUtils.java2Map(bean,"studentScore");
        filedAlias.put("studentScoreList", "studentScore");
        Map<String, Integer> sortMap = new HashMap<>();
        String nestProperties = "studentScore";
        String groupFiled = "studentScore.studentNo";
        SpringDataPageable pageable = new SpringDataPageable(pageIndex, pageSize);
        Page<ExamStudentScoreCalVO> page=examStuScoRepsitory.findNestPage(querParms, filedAlias, sortMap, nestProperties, groupFiled, pageable,
                ExamStudentScoreCalModel.class, ExamStudentScoreCalVO.class);*/
        return page;
    }

    /**
     * 个人成绩分析
     * <p>
     * scoreAyalysModel.ayalysType 分析类型,默认  科目得分分析 1 知识点得分分析 2  小题得分分析 3
     *
     * @author:
     * @date :2017/11/21
     */
    @Override
    public T getScoreAyalyse(ScoreAyalysModel scoreAyalysModel) {
        if ("1".equals(scoreAyalysModel.getAyalysType())) {
            return (T) subjectScoreAyalys(scoreAyalysModel);
        } else if ("2".equals(scoreAyalysModel.getAyalysType())) {
            return (T) getKnowledgeScore(scoreAyalysModel);
        } else {
            return (T) questionScoreAyalys(scoreAyalysModel);
        }
    }

    /**
     * 学生历次单科成绩走势
     *
     * @param compModel
     * @return
     */
    public ServiceResponse StuComperBySubject(StuCompModel compModel) {
        Query query = new Query();
        query.addCriteria(Criteria.where("examId").in(compModel.getExamIds()).and("gradeId").is(compModel.getGradeId())
                .and("classId").is(compModel.getClassId())
                .and("studentScoreList.studentId").is(compModel.getStudentId()));
        List<ExamStudentScoreCalModel> list = examStuScoRepsitory.findListByQuery(query);
        //查询平均分相关
        query = new Query();
        query.addCriteria(Criteria.where("examId").in(compModel.getExamIds()).and("gradeId").is(compModel.getGradeId()));
        List<ExamAvgCalModel> avgList = examAvgRepsitory.findListByQuery(query);
        //转换为考试ID的平均分Map
        Map<String, List<ExamAvgCalModel>> avgMap = avgList.stream().collect(Collectors.groupingBy(ExamAvgCalModel::getExamId));
        List<StudentScoreNumVo> reMo = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            List<StudentScoreCalModel> studentScoreList = list.get(i).getStudentScoreList();
            String exName = list.get(i).getExamName();
            String exId = list.get(i).getExamId();
            studentScoreList = studentScoreList.stream().filter(o -> Objects.nonNull(o)).filter(s -> compModel.getStudentId().equals(s.getStudentId())).collect(Collectors.toList());
            if (studentScoreList != null && studentScoreList.size() == 1) {
                StudentScoreNumVo vo = new StudentScoreNumVo();
                StudentScoreCalModel stu = studentScoreList.get(0);
         /*       vo.setClassSortNum(stu.getClassSortNum());
                vo.setSchoolSortNum(stu.getSchoolSortNum());*/
                vo.setExamId(exId);
                vo.setExamName(exName);
                List<SubujectScoreCalModel> subujectScoreList = stu.getSubujectScoreList();
                subujectScoreList = subujectScoreList.stream().filter(o -> Objects.nonNull(o)).filter(s -> compModel.getSubjectId().equals(s.getSubjectId())).collect(Collectors.toList());
                if (subujectScoreList.size() == 1) {
                    vo.setClassSortNum(stu.getClassSortNum());
                    vo.setSchoolSortNum(stu.getSchoolSortNum());
                    vo.setScore(BigDecimalUtils.round(new BigDecimal(subujectScoreList.get(0).getScore()), 2).doubleValue());
                }
                List<ExamAvgCalModel> avgNow = avgMap.get(exId);
                if (avgNow.size() == 1) {
                    //班级科目平均分
                    List<ExamClassAvgCalModel> examClassAvgModels = avgNow.get(0).getExamClassAvgModels();
                    examClassAvgModels = examClassAvgModels.stream().filter(o -> Objects.nonNull(o)).filter(e -> compModel.getClassId().equals(e.getClassId())).collect(Collectors.toList());
                    if (examClassAvgModels.size() == 1) {
                        List<ExamSubjectAvgCalModel> examSubjectAvgModel = examClassAvgModels.get(0).getExamSubjectAvgModel();
                        //过滤科目
                        examSubjectAvgModel = examSubjectAvgModel.stream().filter(o -> Objects.nonNull(o)).filter(ex -> compModel.getSubjectId().equals(ex.getSubjectId())).collect(Collectors.toList());
                        if (examSubjectAvgModel.size() == 1) {
                            vo.setClassAvgScore(BigDecimalUtils.round(new BigDecimal(examSubjectAvgModel.get(0).getClassAvgScore()), 2).doubleValue());
                        }
                    }
                    //校级科目平均分
                    List<ExamSubjectSchoolAvgCalModel> examSubjectSchoolAvgModelList = avgNow.get(0).getExamSubjectSchoolAvgModelList();
                    examSubjectSchoolAvgModelList = examSubjectSchoolAvgModelList.stream().filter(o -> Objects.nonNull(o)).filter(e -> compModel.getSubjectId().equals(e.getSubjectId())).collect(Collectors.toList());
                    if (examSubjectSchoolAvgModelList.size() == 1) {
                        vo.setSchoolAvgScore(BigDecimalUtils.round(new BigDecimal(examSubjectSchoolAvgModelList.get(0).getSchoolTotalAvgScore()), 2).doubleValue());
                    }
                }
                reMo.add(vo);
            }
        }
        return ServiceResponseHandle.success(reMo);
    }

    /**
     * 个人查询历史考试走势
     *
     * @param compModel
     * @return
     */
    @Override
    public ServiceResponse getCompareExam(StuCompModel compModel) {
        Query query = new Query();
        query.addCriteria(Criteria.where("examId").in(compModel.getExamIds()).and("gradeId").is(compModel.getGradeId())
                .and("classId").is(compModel.getClassId())
                .and("studentScoreList.studentId").is(compModel.getStudentId()));
        List<ExamStudentScoreCalModel> list = examStuScoRepsitory.findListByQuery(query);
        List<StudentScoreNumVo> reMo = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            List<StudentScoreCalModel> studentScoreList = list.get(i).getStudentScoreList();
            String exName = list.get(i).getExamName();
            String exId = list.get(i).getExamId();
            studentScoreList = studentScoreList.stream().filter(o -> Objects.nonNull(o)).filter(s -> compModel.getStudentId().equals(s.getStudentId())).collect(Collectors.toList());
            if (studentScoreList != null && studentScoreList.size() == 1) {
                StudentScoreNumVo vo = new StudentScoreNumVo();
                StudentScoreCalModel stu = studentScoreList.get(0);
                vo.setClassSortNum(stu.getClassSortNum());
                vo.setSchoolSortNum(stu.getSchoolSortNum());
                vo.setExamId(exId);
                vo.setExamName(exName);
                reMo.add(vo);
            }
        }
        return ServiceResponseHandle.success(reMo);
    }

    /**
     * 小题得分分析
     *
     * @author:
     * @date :2017/12/1
     */
    public List<QuestionScoreAyalysVo> questionScoreAyalys(ScoreAyalysModel scoreAyalysModel) {
        Query query = new Query();
        if (StringUtils.isNotEmpty(scoreAyalysModel.getExamId())) {
            query.addCriteria(Criteria.where("examId").is(scoreAyalysModel.getExamId()));
        }
        if (StringUtils.isNotEmpty(scoreAyalysModel.getStudentId())) {
            query.addCriteria(Criteria.where("studentQuestionCalModelList").elemMatch(Criteria.where("studentId").is(scoreAyalysModel.getStudentId())))
                    .fields().include("studentQuestionCalModelList.$");
        }
        //父类文档字段映射
        query.fields().include("examId").include("examName").include("gradeId").include("gradeName")
                .include("subjectId").include("subjectName").include("subjectScore").include("classId").include("className");
        List<ExamSubjectStuQuestionCalModel> list = questionRepsitory.findListByQuery(query);
        list = list.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(comparing(ExamSubjectStuQuestionCalModel::getSubjectId))), ArrayList::new)
        );
        List<QuestionScoreAyalysVo> questionScoreAyalysVos = new ArrayList<QuestionScoreAyalysVo>();//保存科目小题得分情况集合
        if (CollectionUtils.isNotEmpty(list)) {
            for (ExamSubjectStuQuestionCalModel examSubjectStuQuestionCalModel : list) {
                QuestionScoreAyalysVo questionScoreAyalysVo = new QuestionScoreAyalysVo();
                questionScoreAyalysVo.setSubjectName(examSubjectStuQuestionCalModel.getSubjectName());//获取科目
                questionScoreAyalysVos.add(questionScoreAyalysVo);
                List<QuestionScore> questionReceScore = new ArrayList<QuestionScore>(60);//对应科目的小题得分和失分集合
                List<QuestionScore> questionLoseScore = new ArrayList<QuestionScore>(60);//对应科目的小题得分和失分集合
                questionScoreAyalysVo.setQuestionReceScore(questionReceScore);
                questionScoreAyalysVo.setQuestionLoseScore(questionLoseScore);
                //获取小题得分
                List<StudentQuestionCalModel> studentQuestionCalModels = examSubjectStuQuestionCalModel.getStudentQuestionCalModelList();
                if (CollectionUtils.isNotEmpty(studentQuestionCalModels)) {
                    for (StudentQuestionCalModel questionCalModel : studentQuestionCalModels) {
                        //考试科目对应小题信息,学生个人得分情况
                        List<QuestionStuCalModel> questionStuCalModels = questionCalModel.getQuestionStuCalModelList();
                        //按照小题题号升序排序
                        //questionStuCalModels.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList()).sort((question1, question2) -> question1.getQuesNo().compareTo(question2.getQuesId()));
                        //按照失分降序排序
                        questionStuCalModels = questionStuCalModels.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList());
                        questionStuCalModels.sort(Comparator.comparing(QuestionStuCalModel::getLoseScore).reversed().thenComparing(QuestionStuCalModel::getQuesNo));
                        if (CollectionUtils.isNotEmpty(questionStuCalModels)) {
                            for (QuestionStuCalModel questionStuCalModel : questionStuCalModels) {
                                QuestionScore receScore = new QuestionScore();//小题得分.失分
                                QuestionScore loseScore = new QuestionScore();//小题得分.
                                receScore.setQuesNo(questionStuCalModel.getQuesNo());
                                receScore.setScore(BigDecimalUtils.round(new BigDecimal(questionStuCalModel.getReceScore()), 2).doubleValue());
                                loseScore.setQuesNo(questionStuCalModel.getQuesNo());
                                loseScore.setScore(BigDecimalUtils.round(new BigDecimal(questionStuCalModel.getLoseScore()), 2).doubleValue());
                                questionReceScore.add(receScore);
                                questionLoseScore.add(loseScore);
                            }
                        }
                    }
                }
            }
        }

        return questionScoreAyalysVos;
    }

    public static void main(String[] args) {
        java.util.Random random = new java.util.Random();
        System.out.println();
    }

    /**
     * (科目得分分析)
     *
     * @author:
     * @date :2017/11/24
     */
    public StudentScoreAyalysVo subjectScoreAyalys(ScoreAyalysModel scoreAyalysModel) {
        RadarVo radar = getPadar(scoreAyalysModel);
        ReallyScoreVo reallyScore = getReallyScore(scoreAyalysModel, radar.getScoreList());
        PercentScoreVo percentScore = getPercentScore(scoreAyalysModel);
        return new StudentScoreAyalysVo(reallyScore, radar, percentScore);
    }


    /**
     * 获取雷达地图
     *
     * @author:
     * @date :2017/11/18
     */
    public RadarVo getPadar(ScoreAyalysModel scoreAyalysModel) {
        Query query = new Query();
        if (StringUtils.isNotEmpty(scoreAyalysModel.getExamId())) {
            query.addCriteria(Criteria.where("examId").is(scoreAyalysModel.getExamId()));
        }
        if (StringUtils.isNotEmpty(scoreAyalysModel.getStudentId())) {
            query.addCriteria(Criteria.where("studentScoreList").elemMatch(Criteria.where("studentId").is(scoreAyalysModel.getStudentId())))
                    .fields().include("studentScoreList.$");
        }
        query.fields().include("examId").include("examName").include("gradeId").include("schoolId");
        List<ExamStudentScoreCalModel> list = examStuScoRepsitory.findListByQuery(query);
        List<String> subjectList = new ArrayList<String>();
        List<Double> scoreList = new ArrayList<Double>();
        List<Double> precentList = new ArrayList<Double>();
        list = list.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(comparing(ExamStudentScoreCalModel::getExamId))), ArrayList::new)
        );
        list.forEach(item -> {
            List<StudentScoreCalModel> studentScoreList = item.getStudentScoreList();
            studentScoreList.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList())
                    .forEach(studentScore -> {
                        List<SubujectScoreCalModel> subjectScore = studentScore.getSubujectScoreList();
                        subjectScore.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList()).sort((subujectScore1, subujectScore2) -> subujectScore1.getSubjectId().compareTo(subujectScore2.getSubjectId()));
                        subjectScore.forEach(score -> {
                            subjectList.add(score.getSubjectName());
                            scoreList.add(BigDecimalUtils.round(new BigDecimal(score.getScore()), 2).doubleValue());
                        });
                    });
        });
        return new RadarVo(subjectList, scoreList);
    }

    /**
     * 获取科目实际得分与班级评分对比图
     *
     * @param personSubjectScores 个人科目得分
     * @author:
     * @date :2017/11/18
     */
    public ReallyScoreVo getReallyScore(ScoreAyalysModel scoreAyalysModel, List<Double> personSubjectScores) {
        //获取科目实际得分
        Query query = new Query();
        if (StringUtils.isNotEmpty(scoreAyalysModel.getExamId())) {
            query.addCriteria(Criteria.where("examId").is(scoreAyalysModel.getExamId()));
        }
        if (StringUtils.isNotEmpty(scoreAyalysModel.getGradeId())) {
            query.addCriteria(Criteria.where("gradeId").is(scoreAyalysModel.getGradeId()));
        }
        List<String> subjectList = new ArrayList<String>();
        List<Double> clssSubjectScores = new ArrayList<Double>();
        List<Double> gradeSubjectScores = new ArrayList<Double>();
        List<ExamAvgCalModel> list = examAvgRepsitory.findListByQuery(query);
        list = list.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(comparing(ExamAvgCalModel::getExamId))), ArrayList::new)
        );
        list.forEach(examAvgCalModel -> {
            List<ExamClassAvgCalModel> examClassAvgCalModels = examAvgCalModel.getExamClassAvgModels();//获取班级平均分信息
            List<ExamSubjectSchoolAvgCalModel> examSubjectSchoolAvgCalModels = examAvgCalModel.getExamSubjectSchoolAvgModelList();//获取年级科目平均得分信息
            //过滤班级
            examClassAvgCalModels = examClassAvgCalModels.stream().filter(m -> m.getClassId().equals(scoreAyalysModel.getClassId())).collect(Collectors.toList());
            examClassAvgCalModels.forEach(examClassAvgCalModel -> {
                List<ExamSubjectAvgCalModel> examSubjectAvgCalModels = examClassAvgCalModel.getExamSubjectAvgModel();
                if (CollectionUtils.isNotEmpty(examSubjectAvgCalModels)) {
                    examSubjectAvgCalModels.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList()).sort((subujectScore1, subujectScore2) ->
                            subujectScore1.getSubjectId().compareTo(subujectScore2.getSubjectId()));
                    examSubjectAvgCalModels.forEach(item -> {
                        subjectList.add(item.getSubjectName());
                        clssSubjectScores.add(BigDecimalUtils.round(new BigDecimal(item.getClassAvgScore()), 2).doubleValue());
                    });
                }

            });
            if (CollectionUtils.isNotEmpty(examSubjectSchoolAvgCalModels)) {
                examSubjectSchoolAvgCalModels.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList()).sort((subujectScore1, subujectScore2) -> subujectScore1.getSubjectId().compareTo(subujectScore2.getSubjectId()));
                examSubjectSchoolAvgCalModels.forEach(item -> {
                    gradeSubjectScores.add(BigDecimalUtils.round(new BigDecimal(item.getSchoolTotalAvgScore()), 2).doubleValue());
                });
            }

        });
        Series pesonSeries = new Series();
        pesonSeries.setData(personSubjectScores);
        pesonSeries.setName("个人科目得分");

        Series classSeries = new Series();
        classSeries.setData(clssSubjectScores);
        classSeries.setName("班级科目平均分");

        Series gradSeries = new Series();
        gradSeries.setData(gradeSubjectScores);
        gradSeries.setName("年级科目平均分");

        List<Series> seriesList = new ArrayList<Series>();
        seriesList.add(pesonSeries);
        seriesList.add(classSeries);
        seriesList.add(gradSeries);
        return new ReallyScoreVo(subjectList, seriesList);
    }

    /**
     * 获取百分比得分
     *
     * @author:
     * @date :2017/11/18
     */
    public PercentScoreVo getPercentScore(ScoreAyalysModel scoreAyalysModel) {
        Query query = new Query();
        if (StringUtils.isNotEmpty(scoreAyalysModel.getExamId())) {
            query.addCriteria(Criteria.where("examId").is(scoreAyalysModel.getExamId()));
        }
        if (StringUtils.isNotEmpty(scoreAyalysModel.getStudentId())) {
            query.addCriteria(Criteria.where("studentScoreList").elemMatch(Criteria.where("studentId").is(scoreAyalysModel.getStudentId())))
                    .fields().include("studentScoreList.$");
        }
        query.fields().include("examId").include("examName").include("gradeId").include("schoolId");
        List<ExamStudentScoreCalModel> list = examStuScoRepsitory.findListByQuery(query);
        List<String> subjectList = new ArrayList<String>();
        List<Double> scoreList = new ArrayList<Double>();
        List<Double> precentList = new ArrayList<Double>();
        list = list.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(comparing(ExamStudentScoreCalModel::getExamId))), ArrayList::new)
        );
        list.stream().filter(o -> Objects.nonNull(o)).forEach(item -> {
            List<StudentScoreCalModel> studentScoreList = item.getStudentScoreList();
            studentScoreList.stream().filter(o -> Objects.nonNull(o)).collect(Collectors.toList())
                    .forEach(studentScore -> {
                        List<SubujectScoreCalModel> subjectScore = studentScore.getSubujectScoreList();
                        subjectScore.stream().filter(O -> Objects.nonNull(O)).collect(Collectors.toList()).sort((subujectScore1, subujectScore2) -> subujectScore1.getSubjectId().compareTo(subujectScore2.getSubjectId()));
                        subjectScore.forEach(score -> {
                            subjectList.add(score.getSubjectName());
                            precentList.add(BigDecimalUtils.round(new BigDecimal(score.getPercentScore()), 2).doubleValue());
                        });
                    });
        });
        List<Series> seriesList = new ArrayList<Series>();
        Series precent = new Series();
        precent.setName("科目得分率");
        precent.setData(precentList);
        seriesList.add(precent);
        return new PercentScoreVo(subjectList, seriesList);
    }

    /**
     * 获取知识点得分
     * (科目得分分析)
     *
     * @author:
     * @date :2017/11/18
     */
    public KnowledgeScoreVo getKnowledgeScore(ScoreAyalysModel scoreAyalysModel) {
        Query query = new Query();
        if (StringUtils.isNotEmpty(scoreAyalysModel.getExamId())) {
            query.addCriteria(Criteria.where("examId").is(scoreAyalysModel.getExamId()));
        }
        if (StringUtils.isNotEmpty(scoreAyalysModel.getStudentId())) {
            query.addCriteria(Criteria.where("studentPoints.studentId").is(scoreAyalysModel.getStudentId()));
        }
       /* if(StringUtils.isNotEmpty(scoreAyalysModel.getGradeId())){
            query.addCriteria(Criteria.where("classId").is(scoreAyalysModel.getClassId()));
        }
        if(StringUtils.isNotEmpty(scoreAyalysModel.getClassId())){
            query.addCriteria(Criteria.where("gradeId").is(scoreAyalysModel.getGradeId()));
        }*/
 /*       if(StringUtils.isNotEmpty(scoreAyalysModel.getClassId())){
            query.addCriteria(Criteria.where("subjectId").is(scoreAyalysModel.getStudentId()));
        }*/
        List<ExamSubjectStuPointCalModel> list = pointRepsitory.findListByQuery(query);
        list = list.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(comparing(ExamSubjectStuPointCalModel::getSubjectId))), ArrayList::new)
        );
        LinkedHashSet<String> subjectList = new LinkedHashSet<>();//记录科目信息
        List<KnowledgeSeries> seriesList = new ArrayList<KnowledgeSeries>();
        list.stream().filter(O -> Objects.nonNull(O)).collect(Collectors.toList()).forEach(item -> {
            List<Double> knowledgeToalScore = new ArrayList<Double>();//记录知识点总分
            List<Double> receScores = new ArrayList<Double>();//记录知识点得分
            List<Double> loseScores = new ArrayList<Double>();//记录知识点失分
            List<String> knowledges = new ArrayList<String>();//知识点信息
            KnowledgeSeries knowledgeSeries = new KnowledgeSeries();
            subjectList.add(item.getSubjectName());
            knowledgeSeries.setName(item.getSubjectName());
            List<PointCalModel> points = item.getPointList();//获取知识点
            Map<String, Double> pointsToalMap = new HashMap<String, Double>();
            points.stream().filter(O -> Objects.nonNull(O)).collect(Collectors.toList()).sort((point1, point2) -> point1.getPointId().compareTo(point2.getPointId()));//知识点排序
            points.forEach(pointsItem -> {
                // knowledgeToalScore.add(BigDecimalUtils.round(new BigDecimal(pointsItem.getScore()), 2).doubleValue());
                pointsToalMap.put(pointsItem.getPointId(), BigDecimalUtils.round(new BigDecimal(pointsItem.getScore()), 2).doubleValue());

            });
            if (StringUtils.isNotEmpty(scoreAyalysModel.getStudentId())) {
                //获取特定学生的信息
                List<StudentPointCalModel> studentPoints = item.getStudentPoints();//知识点得分情况
                studentPoints = studentPoints.stream().filter(o -> Objects.nonNull(o)).filter(s -> scoreAyalysModel.getStudentId().equals(s.getStudentId())).collect(Collectors.toList());
                studentPoints.forEach(stuPointitem -> {
                    List<PointStuCalModel> pointStuCalModels = stuPointitem.getPointStuList();
                    //按照知识点就那些排序
                    //pointStuCalModels.stream().filter(O -> Objects.nonNull(O)).collect(Collectors.toList()).sort((pointStuCalModel1, pointStuCalModel2) -> pointStuCalModel1.getPointId().compareTo(pointStuCalModel2.getPointId()));
                    //按照知识点得分排序
                    pointStuCalModels = pointStuCalModels.stream().filter(O -> Objects.nonNull(O)).collect(Collectors.toList());
                    pointStuCalModels.sort(Comparator.comparing(PointStuCalModel::getLoseScore).reversed().thenComparing(PointStuCalModel::getPointId));
                    pointStuCalModels.forEach(pointStuCalModelitem -> {
                        knowledgeToalScore.add(pointsToalMap.get(pointStuCalModelitem.getPointId()));
                        knowledges.add(pointStuCalModelitem.getPointName());
                        receScores.add(BigDecimalUtils.round(new BigDecimal(pointStuCalModelitem.getReceScore()), 2).doubleValue());
                        loseScores.add(BigDecimalUtils.round(new BigDecimal(pointStuCalModelitem.getLoseScore()), 2).doubleValue());

                    });
                });
            }
            knowledgeSeries.setLoseScore(loseScores);
            knowledgeSeries.setGetScore(receScores);
            knowledgeSeries.setKonwledgeList(knowledges);
            knowledgeSeries.setTotalScore(knowledgeToalScore);
            seriesList.add(knowledgeSeries);
        });
        return new KnowledgeScoreVo(subjectList, seriesList);
    }


    /**
     * 导入成绩
     *
     * @param scoreReceverModel 成绩 model
     * @param excelFile         导入excel
     * @return
     */
    @Override
    public ServiceResponse addScoreReceverModel(ScoreReceverModel scoreReceverModel, MultipartFile excelFile) throws Exception {
        ImportExcel importExcel = new ImportExcel(excelFile, 0, 0);
        scoreReceverModel = importExcel.getScoreReceverModel(scoreReceverModel);
        ExamPaperModel examPaperModel = this.examPaperRepsitory.findByExamidAndSubjectidAndGradeid(scoreReceverModel.getExamId(), scoreReceverModel.getSubjectId(), scoreReceverModel.getGradeId());
        if (examPaperModel == null) {
            return ServiceResponseHandle.failed("考试信息不存在" + scoreReceverModel.getExamId());
        }
        //获得考试的题目信息
        List<QuestionModel> questionModelList = examPaperModel.getQuestionModelList();
        if (importExcel.getLastCellNum() != questionModelList.size() + 2) {
            return ServiceResponseHandle.failed("上传的excel文件小题总数不匹配");
        }
        //计算实际小题总分
        double totalScore = questionModelList.stream().filter(O -> Objects.nonNull(O)).mapToDouble(e -> Double.parseDouble(e.getScore())).sum();
        ServiceResponse serviceResponse = CmsHttpPostUtil.HttpsGet(studentUrl + scoreReceverModel.getClassId(), new HashMap<>());
        if (serviceResponse.isSuccess()) {
            List<JSONObject> studentList = (List<JSONObject>) serviceResponse.getData();
            if (CollectionUtils.isEmpty(studentList)) {
                return ServiceResponseHandle.failed("该班级未查询到学生信息");
            }
            Map<String, JSONObject> studentMap = studentList.stream().collect(Collectors.toMap(json -> json.getString("studentNo"), student -> student));
            List<StuScoreReceverModel> scoreDetailList = scoreReceverModel.getScoreDetailList();
            if (CollectionUtils.isEmpty(scoreDetailList)) {
                return ServiceResponseHandle.failed("该班级未查询到学生小题成绩信息");
            }
            for (StuScoreReceverModel stuScoreReceverModel : scoreDetailList) {
                JSONObject student = studentMap.get(stuScoreReceverModel.getStudentNo());
                if (student == null) {
                    return ServiceResponseHandle.failed("学生信息不匹配" + stuScoreReceverModel.getStudentNo());
                }
                stuScoreReceverModel.setStudentName(student.getString("studentName"));
                stuScoreReceverModel.setIDCard(student.getString("IDCard"));
                stuScoreReceverModel.setStudentId(student.getString("id"));
                //获取成绩总分
                double sum = stuScoreReceverModel.getScoreDetailList().stream().filter(O -> Objects.nonNull(O)).mapToDouble(e -> e).sum();
                List<Double> scoreDetailList1 = stuScoreReceverModel.getScoreDetailList();
                if (sum > totalScore || sum < 0) {
                    return ServiceResponseHandle.failed("导入学生成绩总分不正确");
                }
                List<StuScoreDetailModel> stuScoreDetailModelList = new ArrayList<>();
                for (int i = 0; i < questionModelList.size(); i++) {
                    QuestionModel questionModel = questionModelList.get(i);
                    Double itemScore = scoreDetailList1.get(i);
                    StuScoreDetailModel stuScoreDetailModel = new StuScoreDetailModel();
                    stuScoreDetailModel.setId(GlobalUtil.createGlobalId());
                    stuScoreDetailModel.setQuestion(questionModel.getQuestionNo());
                    stuScoreDetailModel.setScoreId(stuScoreReceverModel.getId());
                    stuScoreDetailModel.setQuestionScore(itemScore + "");
                    if (itemScore < 0 || itemScore > Double.parseDouble(questionModel.getScore())) {
                        return ServiceResponseHandle.failed("导入学生成绩小题得分不合法");
                    }
                    stuScoreDetailModelList.add(stuScoreDetailModel);
                }
                stuScoreReceverModel.setStuScoreDetailModels(stuScoreDetailModelList);
                stuScoreReceverModel.setTotalScore(sum);
                stuScoreReceverModel.setId(GlobalUtil.createGlobalId());
                stuScoreReceverModel.setScoreDetailList(null);
            }
        }
        //状态
        scoreReceverModel.setId(GlobalUtil.createGlobalId());
        scoreReceverModel.setState(ExamEnum.EXAM_STATUS_PUBLISH.getCode() + "");
        scoreReceverModel.setSchoolId(examPaperModel.getSchoolid());
        scoreReceverModel.setSchoolName(examPaperModel.getSchoolname());
        scoreReceverModel.setSubjectName(examPaperModel.getSubjectname());
        scoreReceverModel.setGradeName(examPaperModel.getGradename());
        scoreReceverModel.setExamName(examPaperModel.getExamname());
        if (logger.isDebugEnabled()) {
            logger.debug("学生成绩信息导入成功" + JSONObject.toJSONString(scoreReceverModel));
        }
        // 删除相同的成绩信息
        this.scoreReceverModelRepository.deleteScoreReceverModelByClassIdAndExamIdAndSubjectId(scoreReceverModel.getClassId(), scoreReceverModel.getExamId(), scoreReceverModel.getSubjectId());
        this.scoreReceverModelRepository.save(scoreReceverModel);
        return ServiceResponseHandle.success(scoreReceverModel);
    }

    @Override
    public ServiceResponse getItemsByExamId(String examId) {
        List<ExamPaperModel> examPaperModels = this.examPaperRepsitory.findByExamid(examId);
        ExamModel examModela = examRepsitory.findOne(examId);
        List<GradeVo> resultList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(examPaperModels)) {
            examPaperModels.stream().collect(Collectors.groupingBy(e -> e.getGradeid() + "-" + e.getGradename())).forEach((k, v) -> {
                String gradeId = k.split("-")[0];
                String gradeName = k.split("-")[1];
                GradeVo infoMap = new GradeVo();
                infoMap.setGradeId(gradeId);
                infoMap.setGradeName(gradeName);
                ServiceResponse serviceResponse = CmsHttpPostUtil.HttpsGet(classListUrl + gradeId, new HashMap<>(16));
                if (serviceResponse.isSuccess()) {
                    List<SubjectVo> examList = new ArrayList<>();
                    v.forEach(examModel -> {
                        SubjectVo examMap = new SubjectVo();
                        examMap.setSubjectId(examModel.getSubjectid());
                        examMap.setSubjectName(examModel.getSubjectname());
                        examList.add(examMap);
                    });
                    List<Map> classMap = (List<Map>) serviceResponse.getData();
                    List<ClassVo> resuList = new ArrayList<>();
                    classMap.forEach(map -> {
                        if (CalTypeEnum.examtype_school.equals(examModela.getExamType())) {
                            ClassVo resultMap = new ClassVo();
                            resultMap.setClassName(map.get("classname") + "");
                            resultMap.setClassId(map.get("id") + "");
                            resultMap.setSubjectList(examList);
                            resuList.add(resultMap);
                        } else {
                            String cid = examModela.getExamUnitModels().get(0).getUnitId();
                            if (cid.equals(map.get("id"))) {
                                ClassVo resultMap = new ClassVo();
                                resultMap.setClassName(map.get("classname") + "");
                                resultMap.setClassId(map.get("id") + "");
                                resultMap.setSubjectList(examList);
                                resuList.add(resultMap);
                            }
                        }
                    });
                    infoMap.setClassList(resuList);
                }
                resultList.add(infoMap);
            });
        }
        return ServiceResponseHandle.success(resultList);
    }

    /**
     * 成绩导入详情
     *
     * @param examId
     * @return
     */
    @Override
    public ServiceResponse importDetails(String examId, String classId, String subjectId) {
        List<ScoreReceverModel> re = scoreReceverModelRepository.findByExamIdAndClassIdAndSubjectId(examId, classId, subjectId);
        ScoreReceverModel rel = new ScoreReceverModel();
        if (re != null && re.size() == 1) {
            rel = re.get(0);
        }
        if (re != null && re.size() > 1) {
            return ServiceResponseHandle.failed("查询失败！请联系管理员");
        }
        return ServiceResponseHandle.success(rel);
    }

    /**
     * 查询考试导入详情
     *
     * @param examId
     * @return
     */
    @Override
    public ServiceResponse ListSubjectDetails(String examId) {
        ImportDetails reData = new ImportDetails();
        ExamModel examModel = examRepsitory.findOne(examId);
        reData.setExamId(examId);
        reData.setExamName(examModel.getExamName());
        reData.setExamType(examModel.getExamType());
        List<GradeList> gLIst = getGradeListByExam(examModel);
        reData.setGradeList(gLIst);
        return ServiceResponseHandle.success(reData);
    }

    public List<GradeList> getGradeListByExam(ExamModel examModel) {
        List<GradeList> gradeList = new ArrayList<>();
        //查询所有导入成绩的班级科目信息
        //List<ScoreReceverModel> scoreReceverModelList = this.scoreReceverModelRepository.findByExamId(examModel.getId());
        //查询成绩导入详情，组装指定返回字段
        DBObject dbObject = new BasicDBObject();
        dbObject.put("examId", examModel.getId());
        BasicDBObject basicDBObject = new BasicDBObject();
        basicDBObject.put("_id", true);
        basicDBObject.put("schoolId", true);
        basicDBObject.put("gradeId", true);
        basicDBObject.put("subjectId", true);
        basicDBObject.put("examId", true);
        basicDBObject.put("classId", true);
        List<ScoreReceverModel> scoreReceverModelList = scoreReceverModelRepository.findForField(dbObject, basicDBObject);
        if (CalTypeEnum.examtype_class.equals(examModel.getExamType())) {
            GradeList grade = new GradeList();
            grade.setGradeId(examModel.getGradeId());
            grade.setGradeName(examModel.getGradeName());
            List<ClassList> classList = new ArrayList<>();
            ClassList classs = new ClassList();
            ExamUnitModel uM = examModel.getExamUnitModels().get(0);
            classs.setClassId(uM.getUnitId());
            classs.setClassName(uM.getUnitName());
            List<SubjectList> subjectList = new ArrayList<>();
            List<SubjectScoreModel> subjectScoreModels = uM.getSubjectScoreModels();
            if (CollectionUtils.isEmpty(subjectScoreModels)) {
                throw new DescribeException("-1000", "导入班级考试，查询参考科目分数信息异常！");
            }
            for (SubjectScoreModel sub : subjectScoreModels) {
                SubjectList s = new SubjectList();
                s.setSubjectId(sub.getSubjectid());
                s.setSubjectName(sub.getSubjectname());
                subjectList.add(s);
            }
            classs.setSubjectList(subjectList);
            isImport(scoreReceverModelList, classs);
            classList.add(classs);
            grade.setClassList(classList);
            gradeList.add(grade);
        }
        //校级考试
        else {
            List<ExamUnitModel> listUn = examModel.getExamUnitModels();
            for (ExamUnitModel u : listUn) {
                GradeList grade = new GradeList();
                grade.setGradeId(u.getUnitId());
                grade.setGradeName(u.getUnitName());
                //设置科目信息，校级考试，每个年级的考试科目都一样
                List<SubjectList> subjectList = new ArrayList<>();
                List<SubjectScoreModel> subjectScoreModels = u.getSubjectScoreModels();
                if (CollectionUtils.isEmpty(subjectScoreModels)) {
                    throw new DescribeException("-1000", "导入校级考试，查询参考科目分数信息异常！");
                }
                for (SubjectScoreModel sub : subjectScoreModels) {
                    SubjectList s = new SubjectList();
                    s.setSubjectId(sub.getSubjectid());
                    s.setSubjectName(sub.getSubjectname());
                    subjectList.add(s);
                }
                //设置考试的年级对应的班级信息
                List<ClassList> cla = getAllCalssList(u.getUnitId(), subjectList, scoreReceverModelList);
                grade.setClassList(cla);
                gradeList.add(grade);
            }
        }
        return gradeList;
    }

    public void isImport(List<ScoreReceverModel> scoreReceverModelList, ClassList v) {
        v.getSubjectList().forEach(s -> {
            List<ScoreReceverModel> fm = scoreReceverModelList.stream().filter(sco -> v.getClassId().equals(sco.getClassId()) && s.getSubjectId().equals(sco.getSubjectId())).collect(Collectors.toList());
            if (fm == null || fm.size() == 0) {
                s.setIsImport("1");
            } else {
                //已导入
                s.setIsImport("2");
            }
        });
    }

    /**
     * 通过年级ID获取所有班级信息
     *
     * @param gradeId
     * @return
     */
    public List<ClassList> getAllCalssList(String gradeId, List<SubjectList> ll, List<ScoreReceverModel> scoreReceverModelList) {
        List<ClassList> l = new ArrayList<>();
        ServiceResponse res = CmsHttpPostUtil.HttpsGet(classListUrl + gradeId, new HashMap<>(16));
        Object o = res.getData();
        JSONArray j = JSON.parseArray(JSON.toJSONString(o));
        for (int i = 0; i < j.size(); i++) {
            ClassList v = new ClassList();
            JSONObject js = (JSONObject) j.get(i);
            v.setClassName(js.getString("classname"));
            v.setClassId(js.getString("id"));
            try {
                List<SubjectList> ls = CloneUtil.deepCopy(ll);
                v.setSubjectList(ls);
                isImport(scoreReceverModelList, v);
                l.add(v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return l;
    }

    /**
     * 发布成绩
     *
     * @param examId
     * @return
     */
    @Override
    public ServiceResponse publishScore(String examId) {
        ServiceResponse response = this.getItemsByExamId(examId);
        if (response.isSuccess()) {
            List<GradeVo> list = (List<GradeVo>) response.getData();
            int sum = list.stream().mapToInt(e -> {
                return e.getClassList().stream().mapToInt(e1 -> e1.getSubjectList().size()).sum();
            }).sum();
            //查询所有导入成绩的班级科目信息
            //List<ScoreReceverModel> scoreReceverModelList = this.scoreReceverModelRepository.findByExamId(examId);
            DBObject dbObject = new BasicDBObject();
            dbObject.put("examId", examId);
            BasicDBObject basicDBObject = new BasicDBObject();
            basicDBObject.put("_id", true);
            List<ScoreReceverModel> scoreReceverModelList = scoreReceverModelRepository.findForField(dbObject, basicDBObject);
            if (scoreReceverModelList == null || scoreReceverModelList.size() != sum) {
                return ServiceResponseHandle.failed("成绩还未导入完成，请确认成绩是否导入完成");
            }
            //修改考试状态
            ExamModel examModel = examRepsitory.findOne(examId);
            examModel.setStatus(ExamEnum.EXAM_STATUS_CALTYPE.getCode() + "");
            examModel.setStatusName(ExamEnum.EXAM_STATUS_CALTYPE.getName());
            this.examRepsitory.save(examModel);
            hiSender.sendDataToQueue(MqTopic.ZXY_CACULATE, examId);
        }
        return ServiceResponseHandle.success("", "保存成功");
    }

    @Override
    public ServiceResponse scoreAnalysis(ScoreAnaySizeParam scoreParam) {
        String examId = scoreParam.getExamId();
        List<String> examNames = new LinkedList<>();
        List<Integer> selectValues = new ArrayList<>();
        if (StringUtils.isNotBlank(examId)) {
            String[] examArr = examId.split(",");
            Arrays.asList(examArr).forEach(id -> {
                Map<String, Object> paramMap = new HashMap<>();
                paramMap.put("studentVo.studentId", scoreParam.getStudentId());
                paramMap.put("classId", scoreParam.getClassId());
                paramMap.put("examId", id);
                PersonAnaysizeVo bean = new PersonAnaysizeVo();
                Map<String, String> fieldMap = FiledAliasMapUtils.java2Map(bean, "studentVo");
                fieldMap.put("seleStudentScoreList", "studentVo");
                Page<PersonAnaysizeVo> scoreVoPage = this.seleExamStudentScoreRepsitory.findNestPage(paramMap, fieldMap, "studentVo", "studentVo.studentId", null, SeleExamStudentScoreCalModel.class, PersonAnaysizeVo.class);
                if (CollectionUtils.isNotEmpty(scoreVoPage.getContent())) {
                    PersonAnaysizeVo personAnaysizeVo = scoreVoPage.getContent().get(0);
                    examNames.add(personAnaysizeVo.getExamName());
                    selectValues.add(personAnaysizeVo.getStudentVo().getSelectValue());
                }
            });
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("x", examNames);
        resultMap.put("y", selectValues);
        return ServiceResponseHandle.success(resultMap);
    }

    /**
     *  判断是否计算完成
     * @param examId
     * @return
     */
    @Override
    public ServiceResponse finishCal(String examId){
        ExamModel examModela = examRepsitory.findOne(examId);
        if(examModela==null){
            return ServiceResponseHandle.failed("");
        }
        if(ExamEnum.EXAM_STATUS_PUBLISH.getCode().toString().equals(examModela.getStatus())){
            return ServiceResponseHandle.success("");
        }
        return ServiceResponseHandle.failed("");
    }
    /**
     * 分数段分析
     *
     * @param scoreParam
     * @return
     */
    @Override
    public ServiceResponse footAnalysis(ScoreAnaySizeParam scoreParam) {
        String examId = scoreParam.getExamId();
        List<String> examNames = new LinkedList<>();
        List<Integer> selectValues = new ArrayList<>();
        if (StringUtils.isNotBlank(examId)) {
            String[] examArr = examId.split(",");
            Arrays.asList(examArr).forEach(id -> {
                Map<String, Object> paramMap = new HashMap<>();
                paramMap.put("classId", scoreParam.getClassId());
                paramMap.put("examId", id);
                PersonAnaysizeVo bean = new PersonAnaysizeVo();
                Map<String, String> filedAlias = FiledAliasMapUtils.java2Map(bean, "studentVo");
                filedAlias.put("seleStudentScoreList", "studentVo");
                Page<PersonAnaysizeVo> scoreVoPage = this.seleExamStudentScoreRepsitory.findNestPage(paramMap, filedAlias, "studentVo", "studentVo.studentId", null, SeleExamStudentScoreCalModel.class, PersonAnaysizeVo.class);
                List<PersonAnaysizeVo> content = scoreVoPage.getContent();
                if (CollectionUtils.isNotEmpty(content)) {
                    PersonAnaysizeVo personAnaysizeVo = content.stream().filter(e -> e.getStudentVo().getStudentId().equals(scoreParam.getStudentId())).collect(Collectors.toList()).get(0);
                    examNames.add(personAnaysizeVo.getExamName());
                    Integer footFault = personAnaysizeVo.getStudentVo().getFootFault();
                    footFault = footFault == null ? 400 : footFault;
                    if (GlobalTypeEnum.DOWN.getCode().equals(personAnaysizeVo.getStudentVo().getType())) {
                        selectValues.add(-footFault);
                    } else {
                        selectValues.add(footFault);
                    }

                }
            });
        }
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("x", examNames);
        resultMap.put("y", selectValues);
        return ServiceResponseHandle.success(resultMap);
    }


}
